package com.gr.service.impl;

import com.gr.dao.JarMapper;
import com.gr.entity.Jar;
import com.gr.service.JarService;
import com.gr.util.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class JarServiceImpl implements JarService {
    @Override
    public List<Jar> selectAll() {
        List<Jar> jars=null;
        SqlSession session = null;
        try {
            session = MybatisUtils.getSession();
            JarMapper jm = session.getMapper(JarMapper.class);
            jars = jm.selectAll();

        } finally {
            MybatisUtils.closeSession(session);
        }
        return jars;
    }

    @Override
    public void addJar(Jar jar) {
        SqlSession session = null;
        try {
            session = MybatisUtils.getSession();
            JarMapper jm = session.getMapper(JarMapper.class);
            jm.addJar(jar);
            session.commit();
        } finally {
            MybatisUtils.closeSession(session);
        }
    }
}
